/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package niconico;

import util.DeviceControl;

/**
 *
 * @author tfuru
 */
//http://www.forum.nokia.com/document/Forum_Nokia_Technical_Library/contents/FNTL/Controlling_screen_saver_in_MIDlets_on_S60_devices.htm
public class BackLightThread implements Runnable {

    private boolean m_is_alive;
    private boolean m_on;
    private Thread m_thread;

    public BackLightThread(boolean on) {
        m_is_alive = true;
        m_on = on;
        m_thread = new Thread(this);
    }

    public void setLight(boolean on) {
        this.m_on = on;
    }

    public boolean getLight() {
        return this.m_on;
    }

    public void start() {
        m_thread.start();
    }

    public void shutdown() {
        this.m_is_alive = false;
    }

    public void backLightOnOff() {
        m_on = !m_on;
    }
    
    public boolean isAlive(){
        return m_is_alive;
    }
    
    public void run() {
        try {
            while (m_is_alive) {
                DeviceControl.backLight(m_on);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        } catch (ClassNotFoundException e) {
        }
        m_is_alive = false;
    }
}
